package com.itheima;

import java.util.HashMap;
import java.util.Map;

public class MapPractice {
    public static void main(String[] args) {
        Map<String, String> data = new HashMap<>();
        data.put("a", "A");
        data.put("b", "B");
        data.put("c", "C");
        data.put("d", "D");
        data.put("e", "A");
        data.put("f", "B");
        data.put("g", "C");
        data.put("h", "D");
        data.put("i", "A");
        data.put("j", "B");
        data.put("k", "C");
        data.put("l", "D");
        data.put("m", "A");
        data.put("n", "B");
        data.put("o", "C");
        data.put("p", "D");
        data.put("q", "A");
        data.put("r", "B");
        data.put("s", "C");
        data.put("t", "D");
        data.put("u", "A");
        data.put("v", "B");
        data.put("w", "C");
        data.put("x", "D");

        count(data);
    }
    public static void count(Map<String, String> data){
        // 创建一个map
        Map<String, Integer> resultMap = new HashMap<>();

        data.forEach((k, v) -> {
            boolean ContainKey = resultMap.containsKey(v);
            if (ContainKey){//存在
                Integer oldCount = resultMap.get(v);//获取旧的计数
                resultMap.put(v, oldCount + 1);
            }else {
                resultMap.put(v, 1);
            }
        });
        resultMap.forEach((k, v) -> {
            System.out.println(k+"="+v);
        });


    }
}
